package com.rzt.controller;

import com.rzt.entity.DataSource;
import com.rzt.service.DataSourceService;
import com.rzt.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api("测试数据源")
@RequestMapping("db")
public class TestDBController {

    @Autowired
    private DataSourceService dataSourceService;

    @GetMapping("/listDataBase")
    @ApiOperation("获取数据源")
    public Result<DataSource> listDataBase(){
        List<DataSource> list = dataSourceService.listDataSource();
        return Result.success(list);
    }

    @GetMapping("/addDataBase")
    @ApiOperation("添加数据源")
    public Result<DataSource> addDataBase(){
        dataSourceService.addDataBase();
        return Result.success();
    }

    @GetMapping("/useMoredb")
    @ApiOperation("切换数据源，插入并查询数据")
    @ApiImplicitParam(value = "数据源id",name="id",dataType = "String")
    public Result useMoredb(String id) throws Exception {
        dataSourceService.useMoredb(id);
        return Result.success();
    }
}
